# -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
#    $Id$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from osv import fields
from osv import osv
import wizard
import netsvc
import pooler
import time
from osv.orm import browse_record

class wiz_project_breakdown(wizard.interface):
    
    def _open_breakdown_project(self, cr, uid, data, context):
        #raise osv.except_osv("E",data)
        pool_obj = pooler.get_pool(cr.dbname)
        try:
            prj_id = data['ids'][0]
        except:
            prj_id = data['id']
        
        prj_obj = pool_obj.get('kdvn.project').read(cr,uid,prj_id,['name','code'])
        prj_code = ''
        prj_name = ''
    #    raise osv.except_osv("E",prj_obj)
        
        prj_code = prj_obj['code']
        prj_name = prj_obj['name']
        
        proj_name = ''
        if prj_code:
            proj_name = ": "+ prj_code+" - " + prj_name
        
        value = {
            'name': 'Breakdown for '+proj_name,            
            'url':"/form/view?count=1&domain=[('project_id','=',%s)]&search_domain=&ids=[%s]&view_mode=[u'form']&limit=25&context={'lang':u'en_GB','active_ids':[%s],'tz':u'','_terp_view_name':u'Breakdown for %s','client':'web','project_id':%s,'active_id':3}&offset=0&model=kderp.project.estimated.summary&view_ids=[False]&id=%s" % (prj_id,prj_id,prj_id,proj_name,prj_id,prj_id),
            'type': "ir.actions.act_url",
            'target':'new'
        }
        return value

    states = {
        'init' : {
            'actions' : [],
            'result' : {'type':'action', 'action':_open_breakdown_project, 'state':'end'}
        }
    }
wiz_project_breakdown('wiz_project_breakdown')